#ifndef __RTCSpdu_H_
#define __RTCSpdu_H_

#include "RTCSCString.h"
#include "RTCStype.h"
#include "RTCSbaseObject.h"

#define INVALID_MESSAGEID		0xFFFFFFFF
#define INVALID_TRANID			0xFFFFFFFF
#define INVALID_STATUS			0xFFFFFFFF
#define INVALID_QUALIFIER		0xFFFFFFFF
#define INVALID_ERRORDATA		0xFFFFFFFF

#define INVALID_KEY				0xFFFFFFFF

#define RTCS_constMaxPacketLength	4096

#define RTCS_KVSet_INVALIDTYPE			0xFF
#define RTCS_KVSet_CTbool				1
#define RTCS_KVSet_CTint				2
#define RTCS_KVSet_CTuint				3
				
#define RTCS_KVSet_CTbyte 	           	4
#define RTCS_KVSet_CTfloat 	        	5
#define RTCS_KVSet_CTdouble 	    	6
#define RTCS_KVSet_CTbyteArray          7
#define RTCS_KVSet_CTintArray		    8
#define RTCS_KVSet_CTuintArray 	        9
#define RTCS_KVSet_CTstringArray	    10
#define RTCS_KVSet_CTfloatArray	        11
#define RTCS_KVSet_CTdoubleArray	    12
#define RTCS_KVSet_CTstring             13

//add kvset 
#define RTCS_KVSet_CTkvset				14
#define RTCS_KVSet_CTkvsetArray			15
//add 2uint
#define RTCS_KVSet_CT2uint				16

#define RTCS_KVSet_FTitle               "FST"
#define RTCS_KVSet_FTail                "FND"

class RTCS_CTkeyValueSet;
class RTCS_CTkeyValuePair;
class RTCS_CTkvset;
union RTCS_CTkeyValueUnion;

//##ModelId=3AAC61030012
union RTCS_CTkeyValueUnion
{
	//##ModelId=3AAC61030103
	RTCS_CTbool 		RTCS_CTbool_value;
	//##ModelId=3AAC610300EF
	RTCS_CTbyte 		RTCS_CTbyte_value;
	//##ModelId=3AAC610300DB
	RTCS_CTint	 		RTCS_CTint_value;
	//##ModelId=3AAC610300C7
	RTCS_CTuint 		RTCS_CTuint_value;
	//##ModelId=3AAC610300B5
	RTCS_CT2uint		RTCS_CT2uint_value;
	//##ModelId=3AAC610300A8
	RTCS_CTfloat 		RTCS_CTfloat_value;
	//##ModelId=3AAC61030094
	RTCS_CTdouble 		RTCS_CTdouble_value;
	
	//##ModelId=3AAC61030082
	RTCS_CTbyteArray 	RTCS_CTbyteArray_value;
	//##ModelId=3AAC61030076
	RTCS_CTintArray		RTCS_CTintArray_value;
	//##ModelId=3AAC61030064
	RTCS_CTuintArray 	RTCS_CTuintArray_value;
	//##ModelId=3AAC61030058
	RTCS_CTstringArray	RTCS_CTstringArray_value;
	//##ModelId=3AAC61030046
	RTCS_CTfloatArray	RTCS_CTfloatArray_value;
	//##ModelId=3AAC6103003C
	RTCS_CTdoubleArray	RTCS_CTdoubleArray_value; 
	//add for kvset
	//##ModelId=3AAC61030032
	RTCS_CTkvset		*RTCS_CTkvset_value;
	//##ModelId=3AAC61030028
	RTCS_CTkvsetArray	RTCS_CTkvsetArray_value;
};

//##ModelId=3AAC6104032B
class RTCS_CTkeyValuePair:public RTCS_Node{
public:
	//##ModelId=3AAC61040373
	RTCS_CTuint		key;
	//##ModelId=3AAC61040367
	RTCS_CTuint		type;
	//##ModelId=3AAC6104035D
	RTCS_CTuint		Nelem;
	//##ModelId=3AAC6104034B
	RTCS_CTkeyValueUnion	value;
	//##ModelId=3AAC61040341
	RTCS_CTstring 	RTCS_CTstring_value;

	//##ModelId=3AAC61040386
	RTCS_CTkeyValuePair():key(INVALID_KEY),type(RTCS_KVSet_INVALIDTYPE),Nelem(0){};
	//##ModelId=3AAC61040385
	virtual ~RTCS_CTkeyValuePair();
	//##ModelId=3AAC6104038F
	RTCS_CTkeyValuePair(RTCS_CTkeyValuePair& src);
	//##ModelId=3AAC6104037B
	RTCS_CTkeyValuePair& operator=(RTCS_CTkeyValuePair& src);
};

//##ModelId=3AAC610D0251
class RTCS_CTkeyValueSet{
public:
	//##ModelId=3AAC610D0272
	RTCS_List<RTCS_CTkeyValuePair> data;

	//##ModelId=3AAC610D0298
	RTCS_CTkeyValuePair * Search(RTCS_CTuint key)
	{
		RTCS_CTkeyValuePair * curr = data.Head();
		while(curr)
		{
			if(curr->key==key)
			{
				return curr;
			}
		    curr=data.Next(curr);		 	
		}
		return NULL;
	}

	//##ModelId=3AAC610D028E
	RTCS_CTkeyValueSet();
	//##ModelId=3AAC610D0286
	virtual ~RTCS_CTkeyValueSet();
	//##ModelId=3AAC610D028F
	RTCS_CTkeyValueSet(RTCS_CTkeyValueSet& src);
	//##ModelId=3AAC610D0284
	RTCS_CTkeyValueSet& operator=(RTCS_CTkeyValueSet& src);
};

//##ModelId=3AAC610F0218
class RTCS_CTkvset:public RTCS_CTkeyValueSet
{
public:
	//##ModelId=3AAC610F02AE
	RTCS_CTkvset(){};
	//##ModelId=3AAC610F02AF
	RTCS_CTkvset(RTCS_CTkvset& src);
	//##ModelId=3AAC610F02A9
	virtual ~RTCS_CTkvset();
	//##ModelId=3AAC610F02A7
	RTCS_CTkvset&	operator=(RTCS_CTkvset& src);
public:
	//##ModelId=3AAC610F02A4
	RTCS_CTuint 	kvset2flow(RTCS_CTbyteArray* flow, RTCS_CTuint* length);
	//##ModelId=3AAC610F029D
	RTCS_CTuint		flow2kvset(RTCS_CTbyteArray& flow, RTCS_CTuint* flowlen);

public:
	//##ModelId=3AAC610F029C
	RTCS_CTuint		Clear();
	//##ModelId=3AAC610F0298
	RTCS_CTuint		GetBool(RTCS_CTuint key, RTCS_CTbool* value);
	//##ModelId=3AAC610F0295
	RTCS_CTuint		GetByte(RTCS_CTuint key, RTCS_CTbyte* value);
	//##ModelId=3AAC610F0292
	RTCS_CTuint		GetInt(RTCS_CTuint key, RTCS_CTint* value);
	//##ModelId=3AAC610F028B
	RTCS_CTuint		GetUInt(RTCS_CTuint key, RTCS_CTuint* value);
	//##ModelId=3AAC610F0288
	RTCS_CTuint		Get2UInt(RTCS_CTuint key,RTCS_CT2uint* value);
	//##ModelId=3AAC610F0283
	RTCS_CTuint		GetString(RTCS_CTuint key, RTCS_CTstring* value);
	//##ModelId=3AAC610F0280
	RTCS_CTuint		GetFloat(RTCS_CTuint key, RTCS_CTfloat* value);
	//##ModelId=3AAC610F027D
	RTCS_CTuint		GetDouble(RTCS_CTuint key, RTCS_CTdouble* value);
	//##ModelId=3AAC610F0279
	RTCS_CTuint		GetByteArray(RTCS_CTuint key, RTCS_CTbyteArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610F0275
	RTCS_CTuint		GetIntArray(RTCS_CTuint key, RTCS_CTintArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610F026F
	RTCS_CTuint		GetUIntArray(RTCS_CTuint key, RTCS_CTuintArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610F026B
	RTCS_CTuint		GetStringArray(RTCS_CTuint key, RTCS_CTstringArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610F0267
	RTCS_CTuint		GetFloatArray(RTCS_CTuint key, RTCS_CTfloatArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610F0263
	RTCS_CTuint		GetDoubleArray(RTCS_CTuint key, RTCS_CTdoubleArray* value, RTCS_CTuint* Nelems);

	//##ModelId=3AAC610F0260
	RTCS_CTuint		PutBool(RTCS_CTuint key, RTCS_CTbool value);
	//##ModelId=3AAC610F0259
	RTCS_CTuint		PutByte(RTCS_CTuint key, RTCS_CTbyte value);
	//##ModelId=3AAC610F0256
	RTCS_CTuint		PutInt(RTCS_CTuint key, RTCS_CTint value);
	//##ModelId=3AAC610F0252
	RTCS_CTuint		PutUInt(RTCS_CTuint key, RTCS_CTuint value);
	//##ModelId=3AAC610F024F
	RTCS_CTuint		Put2UInt(RTCS_CTuint key,RTCS_CT2uint value); 
	//##ModelId=3AAC610F024C
	RTCS_CTuint		PutString(RTCS_CTuint key, RTCS_CTstring& value);
	//##ModelId=3AAC610F0247
	RTCS_CTuint		PutFloat(RTCS_CTuint key, RTCS_CTfloat value);
	//##ModelId=3AAC610F0244
	RTCS_CTuint		PutDouble(RTCS_CTuint key, RTCS_CTdouble value);
	//##ModelId=3AAC610F0240
	RTCS_CTuint		PutByteArray(RTCS_CTuint key, RTCS_CTbyteArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC610F023C
	RTCS_CTuint		PutIntArray(RTCS_CTuint key, RTCS_CTintArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC610F0238
	RTCS_CTuint		PutUIntArray(RTCS_CTuint key, RTCS_CTuintArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC610F0233
	RTCS_CTuint		PutStringArray(RTCS_CTuint key, RTCS_CTstringArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC610F022F
	RTCS_CTuint		PutFloatArray(RTCS_CTuint key, RTCS_CTfloatArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC610F0223
	RTCS_CTuint		PutDoubleArray(RTCS_CTuint key, RTCS_CTdoubleArray& value, RTCS_CTuint Nelems);
};


//##ModelId=3AAC6109009D
class RTCS_CTpdu:public RTCS_Node{
public:
	//##ModelId=3AAC61090135
	RTCS_CTuint 	pduVersion;
	//##ModelId=3AAC61090129
	RTCS_CTuint 	sender;
	//##ModelId=3AAC61090117
	RTCS_CTuint		receiver;
	//##ModelId=3AAC6109010B
	RTCS_CTuint		senderObj;
	//##ModelId=3AAC610900F9
	RTCS_CTuint		receiverObj;
	//##ModelId=3AAC610900EF
	RTCS_CTuint		messageID;
	//##ModelId=3AAC610900E3
	RTCS_CTuint		tranID;
	//##ModelId=3AAC610900D9
	RTCS_CTuint		status;
	//##ModelId=3AAC610900C7
	RTCS_CTuint 	qualifier;
	//##ModelId=3AAC610900BD
	RTCS_CTuint		errorData;
	//##ModelId=3AAC610900B3
	RTCS_CTkeyValueSet	messageData;
public:
	//##ModelId=3AAC610A02A8
	RTCS_CTpdu();
	//##ModelId=3AAC610A02A9
	RTCS_CTpdu(RTCS_CTpdu& src);
	//##ModelId=3AAC610A02A7
	virtual ~RTCS_CTpdu();
	//##ModelId=3AAC610A0293
	RTCS_CTpdu& operator=(RTCS_CTpdu& src);

public:
	//##ModelId=3AAC610A0275
	RTCS_CTuint 	pdu2flow(RTCS_CTbyteArray* flow, RTCS_CTuint* length);
	//##ModelId=3AAC610A024E
	RTCS_CTuint		flow2pdu(RTCS_CTbyteArray& flow,RTCS_CTuint *flowlen);

public:
	//##ModelId=3AAC610A024D
	RTCS_CTuint		Clear();
	//##ModelId=3AAC610A0225
	RTCS_CTuint		GetBool(RTCS_CTuint key, RTCS_CTbool* value);
	//##ModelId=3AAC610A0207
	RTCS_CTuint		GetByte(RTCS_CTuint key, RTCS_CTbyte* value);
	//##ModelId=3AAC610A01E9
	RTCS_CTuint		GetInt(RTCS_CTuint key, RTCS_CTint* value);
	//##ModelId=3AAC610A01CB
	RTCS_CTuint		GetUInt(RTCS_CTuint key, RTCS_CTuint* value);
	//##ModelId=3AAC610A01A3
	RTCS_CTuint		Get2UInt(RTCS_CTuint key,RTCS_CT2uint *value);
	//##ModelId=3AAC610A0185
	RTCS_CTuint		GetString(RTCS_CTuint key, RTCS_CTstring* value);
	//##ModelId=3AAC610A0167
	RTCS_CTuint		GetFloat(RTCS_CTuint key, RTCS_CTfloat* value);
	//##ModelId=3AAC610A013F
	RTCS_CTuint		GetDouble(RTCS_CTuint key, RTCS_CTdouble* value);
	//##ModelId=3AAC610A0117
	RTCS_CTuint		GetByteArray(RTCS_CTuint key, RTCS_CTbyteArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610A00E5
	RTCS_CTuint		GetIntArray(RTCS_CTuint key, RTCS_CTintArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610A00B3
	RTCS_CTuint		GetUIntArray(RTCS_CTuint key, RTCS_CTuintArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610A0080
	RTCS_CTuint		GetStringArray(RTCS_CTuint key, RTCS_CTstringArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610A0058
	RTCS_CTuint		GetFloatArray(RTCS_CTuint key, RTCS_CTfloatArray* value, RTCS_CTuint* Nelems);
	//##ModelId=3AAC610A0026
	RTCS_CTuint		GetDoubleArray(RTCS_CTuint key, RTCS_CTdoubleArray* value, RTCS_CTuint* Nelems);
	//add RTCS_CTkvset operate
	//##ModelId=3AAC610903E6
	RTCS_CTuint		GetKvset(RTCS_CTuint key,RTCS_CTkvset *value);
	//##ModelId=3AAC610903B4
	RTCS_CTuint		GetKvsetArray(RTCS_CTuint key,RTCS_CTkvsetArray* value, RTCS_CTuint* Nelems);


	//##ModelId=3AAC61090396
	RTCS_CTuint		PutBool(RTCS_CTuint key, RTCS_CTbool value);
	//##ModelId=3AAC6109036E
	RTCS_CTuint		PutByte(RTCS_CTuint key, RTCS_CTbyte value);
	//##ModelId=3AAC61090350
	RTCS_CTuint		PutInt(RTCS_CTuint key, RTCS_CTint value);
	//##ModelId=3AAC61090332
	RTCS_CTuint		PutUInt(RTCS_CTuint key, RTCS_CTuint value);
	//##ModelId=3AAC61090314
	RTCS_CTuint		Put2UInt(RTCS_CTuint key,RTCS_CT2uint value);
	//##ModelId=3AAC610902EC
	RTCS_CTuint		PutString(RTCS_CTuint key, RTCS_CTstring& value);
	//##ModelId=3AAC610902CE
	RTCS_CTuint		PutFloat(RTCS_CTuint key, RTCS_CTfloat value);
	//##ModelId=3AAC610902B0
	RTCS_CTuint		PutDouble(RTCS_CTuint key, RTCS_CTdouble value);
	//##ModelId=3AAC6109027E
	RTCS_CTuint		PutByteArray(RTCS_CTuint key, RTCS_CTbyteArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC6109024C
	RTCS_CTuint		PutIntArray(RTCS_CTuint key, RTCS_CTintArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC6109021A
	RTCS_CTuint		PutUIntArray(RTCS_CTuint key, RTCS_CTuintArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC610901F2
	RTCS_CTuint		PutStringArray(RTCS_CTuint key, RTCS_CTstringArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC610901C0
	RTCS_CTuint		PutFloatArray(RTCS_CTuint key, RTCS_CTfloatArray& value, RTCS_CTuint Nelems);
	//##ModelId=3AAC6109018D
	RTCS_CTuint		PutDoubleArray(RTCS_CTuint key, RTCS_CTdoubleArray& value, RTCS_CTuint Nelems);
	//add RTCS_CTkvset operate
	//##ModelId=3AAC6109016F
	RTCS_CTuint		PutKvset(RTCS_CTuint key,RTCS_CTkvset& value);
	//##ModelId=3AAC6109013D
	RTCS_CTuint		PutKvsetArray(RTCS_CTuint key,RTCS_CTkvsetArray& value, RTCS_CTuint Nelems);
};

extern void zip_pdu(RTCS_CTpdu &pdu);
extern void unzip_pdu(RTCS_CTpdu &pdu);

#endif
